home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3644 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.4 KB  |  108 lines

  1. Path: news.nstn.ca!news
  2. From: keichele@ac.dal.ca (Klaus Eichele)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: floating point dynamic array
  5. Date: Tue, 30 Jan 1996 18:29:12 GMT
  6. Organization: Dalhousie University
  7. Message-ID: <4ela12$fu3@news.nstn.ca>
  8. References: <310EFD40.2D03@se.cuhk.hk>
  9. NNTP-Posting-Host: rewasylishen.chem.dal.ca
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Lawrence Xiao <hkshiou3@se.cuhk.hk> wrote:
  13.  
  14. >Hi all,
  15.  
  16. >I try to use dynamic array to store series of floating point.  
  17. >But error message returns.  However, there won't be any problem 
  18. >when I change the all the declaration from floating point 
  19. >to integer.
  20.  
  21. >The message I get is:
  22. >"scanf: floating point formats not linked"
  23. >"abnormal program termination"
  24.  
  25. >The program is as follows:
  26.  
  27. >#include <stdio.h>
  28. >#include <stdlib.h>
  29.  
  30. >main()
  31. >{
  32. >    int     n, k;
  33. >    float   *base, *ptr;
  34.  
  35. >    scanf("%d", &n);
  36. >    base=calloc(n, sizeof(float));
  37. >    for(ptr=base, k=0;k<n;k++)
  38. >    scanf("%f", ptr++);
  39. >    for(ptr=base+n, k=0;k<n;k++)
  40. >    printf("%f\n", *(--ptr));
  41. >    free(base);
  42. >}
  43.  
  44.  
  45. >Can anybody here can drew some light on it?
  46.  
  47. >Lawrence
  48.  
  49. Obviously, you are having a Borland compiler. To quote from the
  50. comp.lang.c FAQ (excellent document, by the way, and worth downloading
  51. AND reading):
  52. ===================
  53. 14.13: Turbo C and "floating point formats not linked."
  54.  
  55. Some compilers for small machines, including Borland's (and Ritchie's
  56. original PDP-11 compiler), leave out certain floating point support if
  57. it looks like it will not be needed.  In particular, the
  58. non-floating-point versions of printf() and scanf() save space by not
  59. including code to handle %e, %f, and %g.  It happens that Borland's
  60. heuristics for determining whether the program uses floating point are
  61. insufficient, and the programmer must sometimes insert an extra,
  62. explicit call to a floating-point library routine to force loading 
  63. of floating-point support.  (See the comp.os.msdos.programmer FAQ list
  64. for more information.)
  65. ====================
  66. This problem is well-documented and in the Borland README.TXT, you
  67. will find the following cure:
  68. ====================
  69. Because you can get this error in a number of different ways, check
  70. the following list of potential causes to find out how to resolve the
  71. error. The causes are listed in order of most common to least common.
  72.  
  73.   1.  CAUSE:  Floating point set to <None>.  You have your
  74.       floating point option set to None when it should be set to
  75.       either Fast or Normal.
  76.  
  77.       FIX:  Set Floating Point to Fast or Normal.
  78.  
  79.   2.  CAUSE:  Either the compiler is over-optimizing, or the
  80.       floating-point formats really do need to be linked in because
  81.       your program manipulates floats in a limited and specific
  82.       fashion. Under certain obscure conditions, the compiler will
  83.       ignore floating point usage in scanf() (e.g., trying to
  84.       read into a float variable that is part of an array contained
  85.       in a structure.)
  86.  
  87.       FIX: Add the following to one source module:
  88.  
  89.            extern _floatconvert;
  90.            #pragma extref _floatconvert
  91.  
  92.   3.  CAUSE:  Forgetting to put the address operator & on the scanf
  93.       variable expression. For example,
  94.        float foo;
  95.        scanf("%f", foo);
  96.  
  97.       FIX: Change the code so that the & operator is used where it
  98.       is needed.  For example, the above code should be
  99.        float foo;
  100.        scanf("%f", &foo);
  101.  
  102.  
  103.  
  104. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  105. Klaus Eichele         keichele@ac.dal.ca  
  106. http://ac.dal.ca/~keichele/keichele.html
  107.  
  108.